package template.datasource.druid;


import template.utils.JDBCUtils;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Properties;

public class Demo02 {
    public static void main(String[] args) {
        Connection con = null;
        PreparedStatement pps =null;

        try {
            //加载配置文件
            Properties pp=new Properties();
            //通过加载器获取配置文件
            InputStream is = Demo02.class.getClassLoader().getResourceAsStream("druid.properties");
            pp.load(is);
            //获取连接对象
            con = JDBCUtils.getConnection();


            String sql="insert into account values (null,?,?)";
            pps = con.prepareStatement(sql);
            //赋值
            pps.setString(1,"悟空");
            pps.setInt(2,2000);
            int i = pps.executeUpdate();
            System.out.println(i);

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.close(pps,con);
        }
    }
}
